<!DOCTYPE html>

<html>
	<head>
		<meta charset="utf-8" />
		<title>PutTopic</title>
	</head>

	<body>
		<?php
			if(isset($_GET['idCat']))
				{
					$idCat = $_GET['idCat'];
				}
			else 
				{
					?>
					<script type="text/javascript">
						document.location.href="index.php";
					</script>					
					
					<?php
				}
				
			$requete = "INSERT INTO sujet (id_cat, titre_sujet) VALUES ('" . $idCat . "', '" . $_POST['titre'] . "');";
			
			$mysqli = new mysqli("localhost", "root", "root", "forum");
			
			/* Vérification de la connexion */
			if (mysqli_connect_errno())
				{
    				echo 'Échec de la connexion : ' . mysqli_error();
    				exit;
				}

			if ($response = $mysqli->query($requete))
				{
						echo '<script type="text/javascript">
							document.location.href="affTopic.php?page=1&idCat=' . $idCat . '";
						</script>';
				}
			else 
				{
						echo '<script type="text/javascript">
							document.location.href="index.php";
						</script>';				
					
				}
		?>
	</body>
</html>